Is this code is correct?

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
KISHEN21
 
Posts: 3
Joined: Wed Jan 04, 2023 10:51 am

Is this code is correct?

Post by KISHEN21 »

Code: Select all

void loop()
{
   MQTT_connect();  
Adafruit_MQTT_Subscribe * subscription;
while ((subscription = mqtt.readSubscription(5000)))
     {   
   if (subscription == &Smartlock)
     {
      //Print the new value to the serial monitor
      Serial.println((char*) Smartlock.lastread); 
     }    
   else if (!strcmp((char*) Smartlock.lastread, "Close"))
      {
        digitalWrite(14, LOW);
        Serial.println("Door Unlocked");
        digitalWrite(12, HIGH);
        delay(2000);
        digitalWrite(12, LOW);
    }
   else if (!strcmp((char*) Smartlock.lastread, "Open"))
      {
        digitalWrite(14, HIGH);
        Serial.println("Door Closed");
        digitalWrite(12, HIGH);
        delay(2000);
        digitalWrite(12, LOW);
    }
 }  
}

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is this code is correct?

Post by dastels »

It depends on what you mean by "correct".

Does it compile? Link? Upload? Do what you intend?

Dave

User avatar
KISHEN21
 
Posts: 3
Joined: Wed Jan 04, 2023 10:51 am

Re: Is this code is correct?

Post by KISHEN21 »

Hi,I can able to upload the code.But the code is not working when I connect to the circuit.Im doing IOT solenoid lock.I cant able to control the solenoid lock.

User avatar
sj_remington
 
Posts: 998
Joined: Mon Jul 27, 2020 4:51 pm

Re: Is this code is correct?

Post by sj_remington »

What circuit?

Do you have a suitable driver and power supply for the solenoid?

User avatar
KISHEN21
 
Posts: 3
Joined: Wed Jan 04, 2023 10:51 am

Re: Is this code is correct?

Post by KISHEN21 »

Im using 12v battery for supply
Attachments
Screenshot 2023-01-15 135741.png
Screenshot 2023-01-15 135741.png (69.1 KiB) Viewed 135 times

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: Is this code is correct?

Post by dastels »

I can't make out the pin labels on the boards. Do you have a higher resolution image?

How are you powering the MCU board? What about current specs of the 12v supply and solenoid lock?

Dave

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”