Lamp With Sensors - Sound/Piezo // RF Communication

I am working on a project that is composed of several lamps that switch on and off according to signals they get from the environment through several sensors.
Here I am going to present the circuit for one of the lamps. This lamp is receiving signals from a sensor that is placed in another room (sound sensor) and sends a signal from a piezo sensor to another lamp.

The lamp has one 220V bulb connected to the Arduino through a relay, which I am going to explain in this instructable, and a 12V bulb connected to the micro-controller through a L7805 voltage regulator, which I explained here.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: All the Components

  • 1x Arduino Leonardo or Uno
  • 1x Prototyping shield
  • 1x breadboard
  • 1x Sound sensor (controlled by an Arduino Micro)
  • 1x Piezo (connected to the circuit of the lamp)
  • 1x tilt sensor (in case the lamp falls down)
  • Jumper wires : male to male, female to male
  • 1x L7805 voltage regulator
  • 1x 1m wire
  • 1x switch
  • 1x relay
  • 1x 220V bulb
  • 1x sockets
  • 1x 12V led
  • 1x 5V led
  • 2x rf communication 433 MHz modules transmitter/ receiver with antennas
  • 1x 220 ohm resistor
  • 1x 10K ohm resistor

Tools:

  • Screwdriver
  • Wire scissors
  • Solder
  • Solder iron

Step 2: Clap Sensor Circuit With Arduino Pro Micro

The sound sensor has three pins that should be connected to the micro-controller, from left to right, to the ground, the a digital pin (in my case 15) and to the 5V pin.

The three pins of the RF transmitter should be connected to the micro-controller, from left to right, to a digital pin (in my case 14), to the 5V pin and to the ground.

Wire a led to pin 2 and ground, to check when the signal is transmitted.

Upload the code to the micro-controller and clap or knock on the table.The led should turn on when sound is detected and a message is transmitted.

Notes :

The sound sensor has a potentiometer through which you can adjust it's sensitivity.

I used an Arduino Pro Micro, but theoretically you can use and ATtiny since VirtualWire library supports it.

Step 3: Clap Sensor Code

include

const char *message = "";

int sensor = 15;

int ledc = 2;

int val = 0;

void setup() {

pinMode (sensor, INPUT);

vw_set_ptt_inverted(true);

vw_set_tx_pin(14);

vw_setup(4000);

}

void loop() {

int val =digitalRead (sensor);

if(val==1) {

digitalWrite (ledc,HIGH);

message="C";

vw_send ((uint8_t *)message, strlen(message));

vw_wait_tx();

delay (2000);

}

else {

digitalWrite (ledc,LOW);

}

}

Step 4: How to Connect a 220V Bulb to Arduino With a Relay

You can see how to connect the wire to the switch, sockets and plug in this instructable, from the photos above or in this cool class by Paige Russell.

Typically, a relay has pins on one side (right) and a screw terminal on the other side (left).

Connect the bulb to the screw terminal through the source wire (the ground wire is continuous from plug to socket):

  • the source wire coming from the socket goes in the first position of the terminal block
  • the source wire from the plug/switch goes into the second position of the block

On the pin side of the relay, connect the micro-controller.

The order of the pins may vary from relay to relay. It should be connected to the ground, 5V pin and a digital pin (in my case pin 5) on the micro-controller.

Step 5: Transmitter With Piezo/ Receiver From Clap Sensor

Since I will have several lamps in the installation that will also be communicating with each other, the circuit on the lamp has both a RF receiver and a RF transmitter. However, if your lamp only receives signals from a sensor, you can skip the transmitter.

Also, the final circuit has a tilt sensor added (not in the photos) to ensure the lamp turns off if it falls.

For this circuit I use either an Arduino Uno or an Arduino Leonardo.

I use a protoshield to have several pins for ground and 5V and because I want all the elements of the circuit on top of the micro-controller.

The lamp has three led bulbs:

  • one is on by default (pin 5)
  • one is on when the lamp receives a signal (pin 7)
  • one is on when the lamp sends a signal (pin 3)

The RF transmitter connect to the ground, 5V pin and pin 2.

The tilt sensor connects to ground, 5V pin and pin 4.

The RF receiver has two ground pins:

  • one next to the antenna
  • the rightmost one

Connect whichever one to the ground of the micro-controller.

The Data pin is second from the right and should be connected to a digital pin (in my case, pin 12)

The 5V pin is the fourth one from the right.

Connect the piezo to the ground and an analog pin (ex: A0).

The piezo sensor sends certain values to the micro-controller. When it is pressed, the values are lower. Use Serial.begin to read the values and decide the threshold for sending the signal. I chose 100.

How it works:

    • The 220V bulb (on pin 5) is on when nothing happens.
    • When the lamp receives a message, the led on pin 7 lights up and the pin 5 led turns off.
    • When the piezo is pressed, the led on pin 3 turns on and the lamp sends a message.
    • The tilt sensor is positioned vertically, which corresponds to a low
      reading, so when is on the horizontal it gives a high reading. Basically, as long as the sensor gives a zero value, the lamp can function normally.
    • However, if the lamp is very stable and in a safe place, there is no need for it.
      I will have people walking around it, so no matter how stable it is, it can be knocked down. If you don't want (need) a tilt sensor, just delete de first if clause after void loop and the last } in the code below.


    Step 6: Transmitter/ Receiver Code

    #include <VirtualWire.h>
    int ledP = 5;

    int ledC = 3;

    int ledA = 7;

    int tiltPin =4;

    int sensor = A0;

    int val = 0;

    const char *message = "";

    void setup () {

    pinMode(ledP,OUTPUT);

    pinMode(ledA,OUTPUT);

    pinMode(ledC,OUTPUT);

    pinMode(sensor,INPUT);

    pinMode(tiltPin,INPUT);

    vw_set_ptt_inverted(true);

    vw_set_rx_pin(12);

    vw_set_tx_pin(11);

    vw_setup(4000);

    vw_rx_start();

    }

    void loop () {

    if (digitalRead(tiltPin) == 0) {

    digitalWrite (ledP, HIGH);

    digitalWrite (ledA, LOW);

    digitalWrite (ledC, LOW);

    val = analogRead (sensor);

    if (val < 100) {

    message="Z";

    vw_send((uint8_t *)message, strlen(message));

    vw_wait_tx();

    delay (2000);

    digitalWrite (ledP,LOW);

    for (int i=0;i<10;i++) {

    digitalWrite (ledC, HIGH);

    delay (2000);

    }

    }

    else {

    digitalWrite (ledP, HIGH);

    digitalWrite (ledA, LOW);

    digitalWrite (ledC, LOW);

    }

    uint8_t buf[VW_MAX_MESSAGE_LEN];

    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) {

    if(buf[0]=='C') {

    digitalWrite (ledP, LOW);

    for(int i=0;i<10;i++) {

    digitalWrite(ledA,HIGH);

    delay(2000);

    }

    }

    else {

    digitalWrite (ledP, HIGH);

    digitalWrite (ledA, LOW);

    digitalWrite (ledC, LOW);

    }

    }

    }

    else {

    digitalWrite (ledP, LOW);

    digitalWrite (ledC, LOW);

    digitalWrite (ledA, LOW);

    }

    }

    Step 7: Lamp in Action

    I hope you enjoyed! :)

    Be the First to Share

      Recommendations

      • Made with Math Contest

        Made with Math Contest
      • Multi-Discipline Contest

        Multi-Discipline Contest
      • Robotics Contest

        Robotics Contest

      Discussions