sound trigger relay on arduino nano

HI.

How make arduino code? (and wiring diagram would be really helpful)

i need relay sound triggered ON and on another sound trigger relay OFF, parts i have:

arduino nano 328

sound sensor KY-038

2 relay module ( 2PH63091A )

many thanks

Google "sound sensor KY-038 arduino tutorial" to see how to use the sound sensor. Some of the tutorials will show how to turn an LED on and off using the sound sensor. Controlling the state of an LED is much like controlling a relay. Google "arduino relay tutorial" to read about relays.

There will be sample code that you can use to write your code. Give it a try and if you have trouble, post the code and describe what it does and how that is different from what you want to do. Also a schematic of your setup.

This is not a difficult project

i can make relay light go On or off after sound trigger but relay itself does not switches any ideas why?

here code

Arduino_Sound_Sensor_Relay.ino
const int relayPin = 11;
const int soundPin = 7;

int soundVal = 0;
int relayToggle = LOW;
int previousState = HIGH;

void setup ()
{
pinMode (relayPin, OUTPUT);
pinMode (soundPin, INPUT);
}

void loop ()
{
soundVal = digitalRead(soundPin);
if (soundVal == LOW && previousState==HIGH)
{
relayToggle=!relayToggle;
digitalWrite (relayPin, relayToggle);
}
previousState=soundVal;
}

I need to know about your relay and how it is wired to the Arduino. A datasheet for the relay would help. Can you post a photo and/or a schematic of the project?

here

also if code is correct i would like to know how add 4 sound sensors for 4 relays control. where to change code.

hmm... u don't know how to .... ok never mind

HI,

i have 1 woking scetch with sound sensor and relay on digi pins 3 and 4

how to copy code for all available digital pins ( make 5 sound trigger relay sensors run from 1 arduino nano) namy thanks

int soundSensor = 3;
int relay = 4;
int claps = 0;
long detectionSpanInitial = 0;
long detectionSpan = 0;
boolean lightState = false;

void setup() {
pinMode(soundSensor, INPUT);
pinMode(relay, OUTPUT);
}

void loop() {

int sensorState = digitalRead(soundSensor);

if (sensorState == 0)
{
if (claps == 0)
{
detectionSpanInitial = detectionSpan = millis();
claps++;
}
else if (claps > 0 && millis()-detectionSpan >= 50)
{
detectionSpan = millis();
claps++;
}
}

if (millis()-detectionSpanInitial >= 400)
{
if (claps == 2)
{
if (!lightState)
{
lightState = true;
digitalWrite(relay, HIGH);
}
else if (lightState)
{
lightState = false;
digitalWrite(relay, LOW);
}
}
claps = 0;
}
}

Please read the forum guide in the sticky post, then modify your post above and put in the missing code tags.

The short answer is to use arrays.

But please clarify your idea. Will there be 5 sound sensors, or one sound sensor and 5 "sounds" (different numbers of claps)?

Arrays and loops.

const byte Channels = 5;
const byte SoundSensorPins[Channels] = {3,4,5,6,7};
const byte RelayPins[Channels] = {2,8,9,10,11};

void setup()
{
  for (byte i=0; i<Channels; i++)
  {
    pinMode(SoundSensorPins[i], INPUT);
    pinMode(RelayPins[i], OUTPUT);
  }
}

Good day,

i need full sketch for arduino nano: sound sensor on trigger (about 4 sec beep ) switches relay ON and keeps it on until another identical 4 sec beep is received.

if no sound trigger received withing 2 hours when relay ON, switch relay off ( for safety - optional)

apreciate if it could work with 4-8 sound sensors and 4-8 relays total (1 sound sensor control just 1 relay)

many thanks

do you know how to do it ?

Soleen:
do you know how to do it ?

wait for the AWOL to throw you the sketch please

Soleen:
do you know how to do it ?

I was just setting up my Uno with a button (to mimic a sound sensor which I don't have) and a relay module to code it for you for just one button / relay, but the thread disappeared and Ah, Bisto here we are in a thread where you already have help from 2 weeks ago....

Soon we’ll see the @OP’s code update.

i am verry sorry but it's been a good week now... still no sketch i know they busy, but i need it!

how who and could posible do this for me? no matter what i try to change in code i get errors... i can not do it on myt own. please help meto make scetch and if it goes like this i++ explain witch pins goes to sensor witch to relay
many thanks

Soleen:
i am verry sorry but it's been a good week now... still no sketch i know they busy, but i need it!

I am sorry to disappoint you, but there is no team of expert programmers working on your request for free.

Soleen:
how who and could posible do this for me?

Click "report to moderator" below and ask them to move your post to the "gigs and collaborations" section of this forum. Add an extra post to the thread, saying how much you are willing to pay to have someone else write this code for you.

no matter what i try to change in code i get errors...

The way that it works here is that you post the code that you are having trouble with. Also post the errors that you get and links to the hardware that you are using. Then we can HELP you to get your code and hardware to work the way that you want. The more that you put into it the more help that you can get. No work, no help.