In this Instructable I'll show you how I setup a Photo-resistor, a Relay Shield and a separate circuit that the Relay controls.

I am testing this type of circuit out for a Robo-Carbot that I am designing, and needed a proof of concept, for a part of it. The headlight that I am thinking about is 9V which is too much for an Arduino to operate, by itself.

The Components:

  1. Arduino UNO type Micro-controller.
  2. Relay Shield - I built the Evil Mad Scientist Simple Relay Shield, from a kit.
  3. One Photo-resistor aka LDR.
  4. Mini bread board.
  5. 3 male to male jumper wires that go from the shield to the mini breadboard. Should be Red for +, Black for - and a signal color of your choice.
  6. 10K resistor.
  7. Items for a second circuit, which will include a Power source, and an LED as an example. I will show 2 examples of this.
  8. Visuino by Mitov Software

Step 1: The Preparation - the Shield

Since I used the Simple Relay Shield Kit, I had to solder it together first and the instructions for this are here: Assembly. While the one you choose or have on hand might be different they operate in very similar ways.

It took me about 25 mins to complete this but your time may vary.

Step 2: The Preparation - the Mini Breadboard

This is an easy little circuit that is able to drive the Relay Shield to switch the separate circuit in this plan.

In this step, I used the 10K resistor and the Photoresistor and the 3 male - male jumper wires.

The signal wire is located in between the LDR and the 10K, attaching to the Analog 0 and with the positive going to 3.3V and the negative going to GND on the shield.

Step 3: The Preparation - the Separate Circuit

This separate circuit can be just about anything that, generally is a Voltage and Current that the Arduino class boards can't handle on their own.

My first example is a 3W LED with heat-sink, that I bought through Addicore.

This Circuit just needs a power source and something to drive and you'll be taking the GND wire and inputting it into the Relay and then to the load. While the Positive will still go straight to the load. These are connected to the Common and the N.O. which stands for Normally Open.

My Second example is a 9V battery powering a High Intensity LED strip, as seen in the second photo.

Step 4: The Visual Code - Visuino

This is a very similar to the Steps taken in BioanM's Instructable and you can start by following the beginning with steps #4 though #9: Using Passive Photo Resistor Sensor with Visuino.

In experimenting I started with PhotoResistorLEDControlInstructable.owarduinoPicture 1 and modified it for this project. You can download the ZIP file from the bottom of this Instructable page, then open it Visuino.

You should see, Picture 2, when you when you open it. Then when you scroll down to the bottom of the sketch, you'll see the important bits, Picture 3.

It is good to replace the CompareAnalogValue1, with Schmitt Trigger to improve the switching when the lighting is around the trigger level. To preform this select the component, Picture 4, then tap the DEL key on your keyboard.

Step 5: The Visual Code - Visuino [Schmitt Trigger]

We need to Add a Schmitt Trigger, so in the search box, Picture 1, in the upper right hand corner, start typing "Schmitt" and it should populate with those components, Picture 2. With the search window open hover over them until you find the AnalogSchmittTrigger (Hysteresis) and drag it on to the work-space just to the right of the SubtractValue1. As seen in Picture 3.

Picture 4 shows the drag connection in progress, you just need to click on the white box labeled Out, then drop it on the green box labeled In, Picture 5, shows it connected.

Step 6: The Visual Code - Visuino [Schmitt Trigger - Modifications]

I tried the default number settings for Threshold and Value, but nothing happened when I covered the LDR with my hand. Picture 1 shows the default numbers for those two numbers. On BoianM's advise I lowered the Threshold to 0.1, then I tried raising the Value slowly and found that 0.7, roughly, trips the Relay Shield when my hand is about 7 or 8 inches away from the LDR. These numbers are shown in Picture 2.

Now we can connect the Schmitt Trigger to the pins that the Relay Shield uses for actually switching the Relay. On this shield, it is setup as digital Pin 4, so once again we are going to Drag the Out of the Schmitt Trigger,Picture 3to the In of Pin 4, I also used the Serial Monitor to looks at the numbers that were being fed to the trigger, but that is optional. Picture 4 shows those being connected.

Step 7: Finished and Run...

Picture 1 is how your Visuino projects should look, minus the Serial if you didn't connect it.

The F9 key, will start the Arduino IDE and load the sketch up ready for uploading. Select you board type and COM port and upload it.

With that taken care you should have a working setup as shown in the video. In which I show the distance trigger levels, some the time I am a bit too far away, but if I move my hand down just a bit, it will trigger it.

<p>Congratulations on your first Visuino Instructable :-) Looks nice!</p>
<p>Thank you Boian, I couldn't have done it without you!</p>
<p>You are Welcome! Can't wait to see the next one :-) And I am sure, I am not alone ;-)</p>
<p>Nice relay circuit! Relays are very useful.</p>
<p>Thank you!</p>

About This Instructable




Bio: Computer Tech for 30 years, got interested in Raspberry Pis around 2012 and Arduinos in 2015. Always into Electronics and now creating Projects for others.
More by KurtRoesener:Using the Trinket Pro With the Neo-Pixel Stick With Visuino LCD Shield in Visuino - Tutorial/Experiment Setting Up Visual Studio and Visual Micro for Coding the Arduino. 
Add instructable to: