Im using a elegoo mega 2560 board and a esp-01 wifi card

int tiltRead;
#define buzzer 5 // buzzer at pin 5
int sound=250; // set buzzer sound

void setup()
{
pinMode (A5, INPUT);
pinMode (9, OUTPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
delay (10000);

}
void loop ()
{
tiltRead = digitalRead(A5);
Serial.print("jewel box is open ");
Serial.println(tiltRead);
delay (1000);
if (tiltRead > 0) {
tone(buzzer,sound);
delay (1000);
}
else
(tiltRead < 0);
noTone(buzzer);

{

}

{
above there is my code wich worked fine on the board and getting data in my serial. how can i get this data to thingspeak using this code and these hardwares? or maybe is there another code?please help me guys

What's that for?

Please remember to use code tags when posting code

is for when the tilt valeu reads below 0 the buzzer wont go off. if u have another code for solution im open to use that.

No, it doesn't do that.
You'd know if you'd tested the code

this is what i get in my serial. when i move the telt it gives a valeu of 1 and the buzzer goes of when it gives zero the buzzer doesnt go off.
10:02:56.178 -> jewel box is open 0
10:02:57.179 -> jewel box is open 0
10:02:58.183 -> jewel box is open 0
10:02:59.167 -> jewel box is open 1
10:03:01.197 -> jewel box is open 1
10:03:03.208 -> jewel box is open 1
10:03:05.164 -> jewel box is open 1
10:03:07.189 -> jewel box is open 0
10:03:08.163 -> jewel box is open 0
10:03:09.192 -> jewel box is open 0
10:03:10.203 -> jewel box is open 0
10:03:11.174 -> jewel box is open 0
10:03:12.161 -> jewel box is open 0
10:03:13.166 -> jewel box is open 0
10:03:14.163 -> jewel box is open 0

It's only doing that because of the delay, not because what you have after the "else" :wink:

thank u ill loop it up now

ooh, what is the proper way then if u can help me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.