Saturday 21 December 2013

Sound Sensor with Relay

Creating a "clap on" "clap off" light switch


Warning!

Because we are using mains power i feel i should give a little warning, the picture below shows cut wires with masking tape covering them, masking tape is not enough protective insulation! This was a quick test done in the middle of the night, as you can probably tell from both wires being cut!

Components

A strange sound sensor i found on amazon code HOT UK05, couldn't find a data sheet for this and hardly any information.

A Cheap version of a SainSmart relay module (4 channel).

An LED for debugging.

And a lamp you can cut the wires to.

Sound sensor

I set the sound sensor as a digital input and adjusted the sensitivity using the onboard potentiometer. That way when sound was detected above a certain threshold the pin was set low and this lit the LED up.

Relay module

Heres a really good website with lots of information about relays.

The Circuit


Conclusions

Using the sensor as a digital input it only has two states, on or off, if i wanted more accurate readings and control i would have to use it as an analoge input.

After programming this i feel alot more confident about checking states, last states then toggling a switch.





Wednesday 18 December 2013

LCD Display


Displaying two variables on a SainSmart LCD keypad shield

Intro

Displaying information on an LCD display is something i want to use in future projects.
I am trying to create a menu using the buttons on the shield but this is a little above my programming level at the moment. 

I could have made a simple menu where if i held "down", temperature is displayed or "up", the light level is displayed, however i want to create a "Real Menu" using arrays to store the different things to be displayed on the LCD and counters to control where we are in the menu and what is to be printed to the LCD.

The circuit


Code
Awesome code showing a menu
Good advice
Wiki



Monday 2 December 2013

PIR and Light Sensor to LED


Using two variables to control an event, in this case turning an LED on.

Automatic light

The Plan

Using a photo resistor and a proximity sensor i want to recreate the automatic light!

Photo resistor

When placed in darkness resistance is high and vice versa.
Used in a voltage divider circuit. We analog read the pin giving a reading between 0 and 5 volts which is then assigned a digital value between 0 and 1024. A great video on voltage dividers.



a voltage divider circuit

PIR

Stands for Passive infrared sensor (HC-SR501) 

Left pot. Adjusts sensitivity,  clockwise more sensitivity and vice versa

Right pot. Controls amount of time (delay) between movement and re-trigger i.e. when set to mid point the time between is 5 seconds. This is only useful if not using a micro controller,  however when using a micro controller the delay can be programmed. A more in depth explanation on how they work here


PIR sensor

The circuit


Conclusions

A relay could be wired up and this circuit could be used to control a light with more power.


Sunday 17 November 2013

Ultrasonic distance sensor

The aim of this session is to become familiar with the HC-SR04 distance measuring sensor and have it control a servo.

Original code taken from here

Findings...

So wired it up and pasted the code in... 

It worked, its only really accurate up to 50 cm's (possibly because of the material it was reflecting off, it was pointed towards my window and a curtain) and the "wall" a of piece of paper i was using to test the distances must be at right angles to the sensor otherwise you get a wrong value . How it works is explained here.  


Add a servo...

When i added the servo it would jump around a lot because of the random values returned from the sensor. I wanted a smooth motion i.e. as an object is brought closer to the servo, the servo would move in one direction and vice versa.

How to make it smooth...

I found a smoothing code in the arduino IDE examples i used this to average the values from the sensor so as an object is brought closer to the sensor the values sent from it dont jump from one to another causing the servo to move to quickly from one position to another. I also multiplied the averaged value (the distance in cm) by 1000 then increased the scale to map it with the servo, this made the servo move even smoother. 

The circuit


The three wires leading off go to the servo 

Conclusions

This could be used for obstacle avoidance, proximity applications etc.
The readings could be made even more accurate by adding a temperature pin and changing the value for the speed of sound through the air and using more code.


User manual for HC-SR04
My Code for Arduino ive left the comments as they a relevant if not related.




Wednesday 20 March 2013

To infinity and beyond!

So building on the thermometer, i want it to be displayed on a 4 digit 7 segment display... i want to use a shift register to control the LEDs.. but first im going to have to learn what they are and how to use them.

This is from the arduino website but is condensed into my own report

74HC595 Shift Register

"8-bit serial-in, serial or parallel-out shift register with output latches; 3-state."

So this shift register is 8 bit, it can access 8 bits of information in a single machine instruction. Because each bit has two possible states "on" and "off" and there are 8 bits, this gives 256 possible combinations... e.g. 2*2*2*2*2*2*2*2 = 2^8


Serial output

Uses "synchronous serial communication" which means we can pulse one pin on and off communicating a data byte, bit by bit, the bits are separated by pulsing the clock pin.

Parallel output

"asynchronous communication" uses the Serial.begin() function of arduino, the data rate must be set on the sender and receiver. When the whole byte (8bits) are received the register deals them out to each output pin, then they are executed at the same time.


Connecting another

There is an option to use the serial out pin the transmit the serial information out to another register unchanged. Meaning you can transmit 16 bits of information where the first 8 will be passed though the first chip and expressed in the second.


3 states

Means HIGH, LOW and high impedance. This means the entire chip is set to low current, high voltage. Its uses include an LED array that might need to be controlled by different micro controllers depending upon its setting.

The Pin-Outputs are.....


PINS 1-7, 15Q0 " Q7Output Pins
PIN 8GNDGround, Vss
PIN 9Q7"Serial Out
PIN 10MRMaster Reclear, active low
PIN 11SH_CPShift register clock pin
PIN 12ST_CPStorage register clock pin (latch pin)
PIN 13OEOutput enable, active low
PIN 14DSSerial data input
PIN 16VccPositive supply voltage

What happens inside the chip?

When the clockPin (SH_CP) switches from LOW to HIGH the shift register reads the state of the dataPin (DS). When the shift register is full the latch is switched to HIGH this sends the information to the storage register then to the outputPins.. The rabbit hole gets deeper... 



Creating a circuit




Turning it on

GND (pin 8) to ground
Vcc (pin 16) to 5V
OE (pin 13) to ground
MR (pin 10) to 5V

Connect to Arduino

DS (dataPin) (pin14) to Arduino DigitalPin 11
SH_CP (clockPin) (pin 11) to Ardunio DigitalPin 12
ST_CP (latchPin) (pin 12) to Arduino DigitalPin 8

So whats next..?

Well the code in example two looks interesting i can type a number into the serial and the corresponding LED will illuminate( Pin 15 is 1). I can see how the hardware side works, now ive got to work on the programming..


Phillip`s data sheet for 74HC595


Monday 18 March 2013

First post, One and a half sugars please

So this is my first blog its more of a log for myself, of my experiments and projects so i know what ive done and how ive done it.


Thermometer:

The temp sensor used is TMP36 the middle signal pin connects to analog input 0 on the arduino.

It outputs 10millivolts per degree c... to allow minus temps it has a 500mV offsett meaning 25c = 750mV, 0c = 500mV..

Convert this from a digital signal analog signal to degrees using maths functions, then displayed using the IDE debug window though a serial connection.





The code used was..


int temperaturePin = 0;    // pins and corresponding inputs are assigned

void setup()    // runs once 
{
    Serial.begin(9600); // initiates serial connection with comp 
}

void loop() // loops over and over
{
    float temperature = getVoltage(temperaturePin);    // float stores the voltage from
                                                                                             // temperaturePin

    temperature = (temperature - .5) * 100;                    // because the offset.. 0c = 500mV
                                                                                            // and each degree is 10mV..
                                                                                            // converts voltage into temp
                                                                                            
    Serial.println(temperature);                                        // prints the result in degrees
    delay(1000);                                                                 // delay
}

    float getVoltage(int pin){                                           // converts from 0 to 1023 digital range
    return (analogRead(pin)  * .0048828814);              // to 0/5 volts each 1 dig range = 5mV
}