Introduction: LaserCat - IoT With NodeMCU & Blynk

About: Engineer, writer and forever student. Passionate to share knowledge of electronics with focus on IoT and robotics.

This is a very simple project, where the main idea is to explore how to control servos via the internet. For that, we will use a great couple of devices, the NodeMCU ESP12-E and a Blynk app.

The project was based it on the great original Instructable: Smartphone Controlled Cat Laser. The original project was developed using an Arduino Uno and its Serial connected toa a PC. Here I adapted it to the NodeMCU, where you can use the device in a more portable way with WiFi and battery.

WARNING: The laser pointer can be dangerous for eyes if directly pointed to them. Protect yours, others and your animal's eyes. Use with care.

Bellow, we can see the cat playing with laserCat:

Step 1: Bill of Material

Step 2: Pan/Tilt Mecanism

Let's built a very simple Pan/Tilt mechanism, mounting the servos "one on top of the other" as shown in the pictures.

  1. The Pan Servo is used "as base". Keep it on Vertical.
  2. Fixed the Tilt Servo over the move part of Pan Servo (in horizontal position)
  3. fixed the Laser Pointer at the "Tilt Servo" move part as shown.

Note that I used some used metal parts of a disassembled toy as base structure for the Pan/Tilt mechanism

Step 3: The HW

The circuit is very simple.

Before you start the connections, take in consideration that the nodeMCU is powered with 5V, but it works internally (and its pins) with 3.3V. So, the Servos should not be sourced from one of its 3.3V output. The exception is the "Vin pin", that can be either drive 5V to the breadboard +VCC rail or power the NodeMCU id an external source is used.

The laser Point module should be powered with 5V, but here the 3.3V digital output of NodeMCU was enough to power it. BTW, doing that the laser power is lower and its use safer.

WARNING: The laser pointer can be dangerous for eyes if directly pointed to them. Protect yours, others and your animal's eyes. Use with care.

  1. Connect the Pan servo data ("X" axis) to the NodeMCU Pin D1 (note that all digital pins of NodeMCU are PWM)
  2. Connect the Tilt servo data ("Y" axis) to the NodeMCU Pin D2
  3. Connect the "S" pin of Laser Pointer to NodeMCU Pin D3
  4. Connect the "Vin" Pin of NodeMCU to Breadboard +5V Rail
  5. Connect the NodeMCU, Servos and Laser Pointers GND's to Breadboard GND Rail
  6. Connect the +5V Servos pins to Breadboard +5V Rail

The above circuit diagram shows the proper connections.

Step 4: The Code

For the servo's control, we will use the library Servo.h, that will generate PWM signals easily positioning them with angular inputs.

Once the base of the project is to use BLYNK, the code became very simple. We must define 4 virtual variables:

V0: "X position"

V1: "Y position"

V2: "Random or manual" operation

V3: Laser ON/OFF command

BLYNK_WRITE(V0) 
{
  xPotReading = param.asInt();
}
BLYNK_WRITE(V1) 
{
  yPotReading = param.asInt();
}
BLYNK_WRITE(V2) 
{
  randState = param.asInt();
}
BLYNK_WRITE(V4) 
{
  laserState = param.asInt();
}

If you do not know how the NodeMCU works with ARDUINO IDE, please see my tutorial:

From blink to Blynk, an IoT jorney on the wings of NodeMCU ESP-12E

Bellow the complete code. Go thru it. It is very simple to understand.

Step 5: Blynk

Step 6: Conclusion

As always, I hope this project can help others find their way in the exciting world of electronics and IoT!

For more projects, please visit my blog: MJRoBot.org

Saludos from the south of the world!

See you at my next instructable!

Thank you

Marcelo

IoT Builders Contest

Participated in the
IoT Builders Contest

Circuits Contest 2016

Participated in the
Circuits Contest 2016