How to make a Tachometer for bicycle

To make a tachometer for bicycle tachometer we will be using Arduino and reed switch as the main component. We will design the tachometer to Display Speed and also temperature. Following are the list of components required.

Parts list:

• Arduino
• Bicycle with reed switch
• LCD display 16×2
• thermometer DS18B20
• Servo
• resistor 1.2k Ω , 4.7k Ω
• potentiometer 10 kΩ
• Miscellaneous – 9V battery, cables, switch, button
• Enclosure

Note that you can omit the Servo if you do not want to display speed in graphical way.

You may refer my earlier post on how to connect LCD display, measure temperature using DS18b20 sensor and how to control servo using Arduino

How to connect 16*2 LCD display Arduino UNO

How to Measure temperature with Arduino and DS18B20 sensor?

Servo Motor Control using Arduino

Step 1: Connecting the LCD display

• VSS –> GND Arduino
• VDP –> 5V Arduino
• VO –> output potentiometer (potentiometer VCC -> 5V Arduino, potentiometer GND -> Arduino GND).
• RS –> pin 12 Arduino
• RW –> GND Arduino
• E –> pin 11 Arduino
• D4 –> pin 5 Arduino
• D5 –> pin 4 Arduino
• D6 –> pin 3 Arduino
• D7 –> pin 2 Arduino
• A –> 5V Arduino with 1.2 k resistor
• K –> GND Arduino

Step 2: Connecting the Servo

• VCC –> 5V Arduino
• mass –> GND Arduino
• Data –> pin 6 Arduino

Step 3: Connecting the Thermometer

• VCC –> 5V Arduino
• mass –> GND Arduino
• Data –> pin 1 Arduino

data and power is connected via a 4.7 kΩresistor

Step 4: Sensor on wheel (reed switch)

• one end -> 5V Arduino
• second end -> A0 Arduino and resistor 1.2 kΩ

The other end of the resistor to ground in the Arduino

Step 5: Connect the Button

• one end –> 5V Arduino
• second end –> A1 Arduino

If you have a different wheel diameter you have to change it. You can calculate it with this formula:

circuit = π*d*2,54 (d=diameter of your wheel, I multiplied it by 2.54 to get the result in meters).

```//Code
#include  < Servo.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 1
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//LCD display pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//servo name
Servo myservo;
//definition of variables
long previous, triptime, time, impulses;
float speedometer, dist, aspeed;
int servo;
int screen=1;
//If you have other diameter of wheel you need change it
float circuit=2.0;
double temperature;

void setup() {

lcd.begin(16, 2);
pinMode(A0, INPUT);
pinMode(A1, INPUT);

//servo definition and setting the tachometer to 0
myservo.attach(6);
myservo.write(180);
lcd.print("Bike tachometer");
delay(1000);
lcd.setCursor(5, 1);
lcd.print("V 1.0");
delay(4000);
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print("Dist:");
}

void loop() {
//if wheel turns
//number of turns++
impulses++;
//count turn time
time=(millis()-previous);
//count speed
speedometer=(circuit / time)*3600.0;
previous=millis();
Tachometer();
delay(100);
}

Lcd();
}

//display speed on tachometer
void Tachometer(){
//map speed 0-180 to servo
speedometer=int(speedometer);
servo = map(speedometer, 0, 72, 180, 0);
//setup servo
myservo.write(servo);
}

void Lcd(){
//when button is clicked
lcd.clear();
screen++;
if(screen==5){
screen=1;
}
}

if(screen==1){
//displays speed
lcd.setCursor(0, 1);
lcd.print("Speed:");
lcd.setCursor(7, 1);
lcd.print(speedometer);
lcd.print("km/h");
}

if(screen==2){

//displays themperature
temperature=sensors.getTempCByIndex(0);
sensors.requestTemperatures();
lcd.setCursor(0, 1);
lcd.print("Temp:");
lcd.setCursor(7, 1);
lcd.print(temperature);
lcd.print(" C");
}

if(screen==3){
//displays averagr speed
aspeed=dist/(millis()/1000.0)*3600.0;
lcd.setCursor(0, 1);
lcd.print("A.speed:");
lcd.setCursor(8, 1);
lcd.print(aspeed);
lcd.print("km/h");
}

if(screen== 4){
//diplays trip time
triptime=millis()/60000;

lcd.setCursor(0, 1);
lcd.print("Time:");
lcd.setCursor(7, 1);
lcd.print(triptime);

}

lcd.setCursor(0, 0);
lcd.print("Dist:");
//calculation of the distance
dist=impulses*circuit/1000.00;
//dislays distance
lcd.setCursor(6,0);
lcd.print(dist);
lcd.print("km");
}

```

Cut the image below and stick on top of the enclosure. You need to position the servo at the Centre. Movement of the arm will indicate the speed in the tachometer for bicycle. To make it simple you can omit this part and just use the LCD to display the speed and distance only. Temperature display is also optional. May be you can add extra features one by one.

Home Automation using Arduino UNO

In this post we will be designing home automation using Arduino UNO and IR remote control device.

Components Required

• Arduino UNO board
• TSOP 1738 IR Remote Control Receiver
• 1 KΩ Resistor X 4
• 2N2222 NPN Transistor X 4
• 1N4007 Diode X 4
• 12 V Relay X 4 – relay board
• Remote Control
• Connecting wires
• 12 V Power supply

Here for remote control we will be using old TV remote.

How it works?

In this project, home automation system controls 4 different appliances with the help of a TV Remote. The working of the project is explained below.

The TSOP1738 IR Receiver Module has a built – in photo receiver, band pass filter and de-modulator. The output of the module can be readily read by a micro-controller. It supports a carrier frequency of 38 KHz. Hence, the carrier frequency of the source i.e. the remote control must be in the range of 38 KHz for it to demodulate.

First step is to decode the data from the remote control using TSOP1738 and Arduino UNO. For that, we need to use a special library called “IRremote”. Download this library from Arduino-IRremote and place it in the libraries folder of Arduino.

The next step is to decode the data of each key of the remote. For this, we will use some functions in the “IRremote” library. The following program will help us in decoding the data from each key of the remote.
NOTE: The following program is an example sketch from the “IRremote” library.

```#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
}
delay(100);
}
view raw```

After decoding the keys, we will write the code for our final home automation system using Power key and numeric keys 1 to 4 to control 4 loads. Numeric keys will control individual loads i.e. key 1 can be used to turn ON or OFF load 1 and so on. Power key will turn ON or OFF all the loads at once.

In the code, we will compare the pressed key against the decoded values which we got earlier. If the key is matched, the corresponding load is turned ON. If the same key is pressed once again, the load is turned OFF. Similar operation is applicable for all the other keys.

Sample code

```#include <IRremote.h>
const int RECV_PIN=11;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define IN1 3
#define IN2 4
#define IN3 5
#define IN4 6
bool i=false;
bool j=false;
bool k=false;
bool l=false;
bool m=false;
void setup()
{
Serial.begin(9600);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
irrecv.enableIRIn();

}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value,HEX);
delay(100);
/////////////////////////
if(results.value==0x40BD00FF)
{
i=!i;
digitalWrite(IN1, i);

}
////////////////////////
if(results.value==0x40BD807F)
{
j=!j;
digitalWrite(IN2, j);
}
if(results.value==0x40BD40BF)
{
k=!k;
digitalWrite(IN3, k);
}
//////////////////////////////
if(results.value==0x40BDC03F)
{
l=!l;
digitalWrite(IN4, l)
}
//////////////////////
if(results.value==0x40BD28D7)
{
m=!m;
digitalWrite(IN1, m);
digitalWrite(IN2, m);
digitalWrite(IN3, m);
digitalWrite(IN4, m);

}
irrecv.resume(); // Receive the next value
}
}```

How to set-up Wireless on your Raspberry Pi

Step 1: Configuring WLAN Connection

Connect you USB Wifi adapter to your Raspberry Pi. Also, ensure that you are already connected to Ethernet cable. Boot your Pi int GUI and open the terminal window. Either directly on the Pi or through SSH.

Next, check that the USB dongle is detected by your Raspberry Pi – enter the command lsusb and check the results. The Wi-Fi device should be listed as shown below:

On the desktop, double-click WiFi Config and select wlan0 as the adapter. On the Current Status tab click Scan and wait for the results. All nearby wireless networks will be listed in a new window.

Select the network you wish to connect to, enter the password in the PSK field and then click Connect. Within seconds, your Raspberry Pi should be connected relentlessly, and you can remove the Ethernet cable.

Step 2: Ensuring Wireless Adapter Connects At Start-up

When you re-boot or shut down and start your Pi again, wireless adapter will not automatically connect. Therefore, if you try to connect via SSH or VNC you will not be able to do so.

To resolve this problem, we will modify network interface file. follow the following steps in your terminal window.

sudo cp /etc/network/interfaces /etc/network/interfaces.old

This will copy the existing interfaces file, renaming it to interfaces.old. If any problem occur with the edits you make, the original can be renamed and restored.

Next, open the interfaces file in a text editor such as vi:

sudo vi /etc/network/interfaces

Update the section dedicated to your wireless device, replacing as mentioned below:

auto wlan0

allow-hotplug wlan0

iface wlan0 inet manual

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

sudo shutdown -r now

After the change restart the Pi. Refer the screenshot below:

When the device reboots, the USB wireless dongle will automatically connect to the previously configured network!

How to get equalizer settings in Windows 10?

You are running windows media player 12 are trying to find out the equalizer settings. To get equalizer settings in Windows 10

Step 1 : Start windows media player

Step 2: Select skin as Revert.

On the menu  click on view -> Skin Chooser and select Revert as shown below

Now you have an equalizer as show below.

Time delay relay circuit

What is a time delay relay circuit?

In a time delay relay circuit, relay contacts are closed or open after the preset time interval. Whereas in a normal relay contacts are open/closed immediately when coil is energized. It prevents the damaging effect of voltage spikes or input surge current by delaying the relay on/off.

Schematic diagram

Components list

• 12v Relay
• Transistor TIP122
• D1 – IN4007
• D2 – Zener diode 3.3v
• VR1 – 100K
• R1,R2,R3 –  1K
• R4 – 330 Ohm
• C1 – 1000 μF 25 v
• C2 – 100 μF 25 v
• LED – 2 nos

How it works ?

The circuit is based on RC time delay and zener controlled switch. When the power to the circuit is switch on, the 1000 μF capacitor charges through 100 k VR. Once the charge through the capacitor reaches 3.3 v zener diode starts conducting. As the zener is connected to the base of transistor, it triggers the transistor and it is turned on. The relay connected to the transistor is energized. The delay in the relay can be controlled by the VR 100K.

1 Watt audio amplifier for Mobile device

1 Watt audio amplifier for mobile device has been designed using LM4890 power amplifier. LM4890 is primarily designed for mobile phones and other portable devices. It is capable of delivering 1 watt of continuous average power to an 8 ohm load from 5v power supply. It has a distortion of less than 1%.

LM4890 does not require output coupling capacitors and therefore ideally suited for mobile phones and other low voltage applications where minimal power consumption is primary requirement. Power output at 5v is 1 watt and at 3.3 v it is approximately 0.4 watt.

Parts required.

• C1= 1 μf 16v
• C2=0.39 μF 50v
• C3=1 μf 16 v
• C4=25 pf
• R1, R2, R3 = 20 k
• J1 an dJ2 = Jumper head vertical mount
• Speaker – 8 Ω

Real time clock with DS1302

Real time clock with DS1302 is designed using Arduino Uno.

The DS1302 is a trickle-charge timekeeping chip containing a real-time clock/calendar and 31 bytes of static RAM. It communicates with a microprocessor via a simple serial interface. The real-time clock/calendar provides seconds, minutes, hours, day, date, month, and year information. DS1302 requires only three wires to communicate with the clock/RAM: CE, I/O (data line), and SCLK (serial clock). It has dual power pins, one for primary and another for backup.  In this example the Primary power will be provided by the Arduino, and the back up by a CR2032 battery.

During reading, the clock could rollover. That would result in bad clock data. To prevent that, the DS1302 has a buffer to store the clock data. That buffer can be read in a single communication session, called a “burst” mode.

The Year data of the DS1302 is only two digits (0-99). The Year ‘0’ is 2000, and not 1970. It has a Leap-Year compensation from 2000 up to 2099 (for a value of 0-99).The data in this ram will get lost if the Arduino is off, and the battery gets empty.

What is required to build the real time clock?

You will need following parts/components

• Arduino Uno
• DS1302 Module
• Button cell

How to connect to Arduino?

The DS1302 can be easily connected to the Arduino. Three pins are needed for the interface (CE, I/O, SCLK), and Vcc2 should be connected to +5V (or +3.3V). The Vcc1 is for a battery .

A crystal of 32.768kHz should be connected to X1 and X2.

The DS1302 can run with a voltage from 2.0V to 5.5V.

Sample Code

```// Example sketch for interfacing with the DS1302 timekeeping chip.
#include <stdio.h>
#include <DS1302.h>
namespace {
// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip.
//
const int CePin   = 5;  // Chip Enable
const int IoPin   = 6;  // Input/Output
const int SclkPin = 7;  // Serial Clock

// Create a DS1302 object.
DS1302 rtc(CePin, IoPin, SclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Sunday";
case Time::kMonday: return "Monday";
case Time::kTuesday: return "Tuesday";
case Time::kWednesday: return "Wednesday";
case Time::kThursday: return "Thursday";
case Time::kFriday: return "Friday";
case Time::kSaturday: return "Saturday";
}
return "(unknown day)";
}
void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
// Print the formatted string to serial so we can see the time.
Serial.println(buf);

}
}  // namespace
void setup() {
Serial.begin(9600);
// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn't always be called. See the DS1302
// datasheet for details.

//  rtc.writeProtect(false);

// rtc.halt(false);
// Make a new time object to set the date and time.
// This need to be done first time to set the Date and time.
// Thursday, July 6, 2017 at 22:58:50.
// Time t(2017, 07, 6, 22, 58, 50, Time::kThursday);
// Set the time and date on the chip.
// rtc.time(t);
}
// Loop and print the time every second.
void loop() {
printTime();
delay(1000);
}```

DS1302 Datasheet: http://datasheets.maximintegrated.com/en/ds/DS1302.pdf

In the next Post I will modify this to make Alarm clock using LCD display.

How to Install Linux Bash shell on Windows 10

Latest windows update allows you to have a full Ubuntu-based Bash shell. This allows you to run the Bash shell and the exact same binaries that you would normally run on Ubuntu Linux.

To get started with bash make sure you are using correct version of Windows.

We would need Windows 10 creators update and a 64 bit version of the Windows 10.

Install Linux bash shell

To install Linix bash shell on windows follow the following steps.

Step 1 – Activate the developer mode

Update & Security > For Developers. Activate the “Developer Mode” as shown below:

Step2: Enable the Windows Subsystem for Linux (Beta)

Next, open the Control Panel, click “Programs,” and click “Turn Windows Features on or Off” under Programs and Features. Enable the “Windows Subsystem for Linux (Beta)” option in the list here and click “OK.” After this it will ask you to reboot.

Step 3:

After your computer restarts, open windows command prompt and type bash as shown below. The first time you run the bash.exe file, it will prompt to accept the terms of service. The command will then download the “Bash on Ubuntu on Windows” application from the Windows Store. It will ask you to create a user account and password for use in the Bash environment.

What can you do with bash shell on windows?

• You would be able to use standard Linux SSH utility and discard third party tool like putty.
• You will be able to edit text with VIM from the command line, and manipulate text using Sed and Awk.
• You can also, apt-get to manage their packages, and to install tens of thousands of Ubuntu binaries.
• Basically its good utility for developer/administrators. These may not be very useful to general users. But if you are interested in learning Linux you can start it from here without going into the complexity to install LINUX.

Seven segment display counter

A seven segment display is typically used to display numbers from 0-9. It consists of 7 bar segments and a dot( 8 Segments). They are numbered A to F and DP for the dot or decimal place. There are 2 types of 7 Segment display

• Common anode
• Common cathode

Seven Segments are labelled as below.

For more detail on 7 segment display refer my blog post on it here.

To display number we need to turn on the correct segments as shown below:

```0- ABCDEF
1- BC
2- ABGED
3- ABCDG
4- BCFG
5- ACDFG
6- ACDEFG
7- ABC
8- ABCDEFG
9- ABCFG```

List of Parts needed

1. Common cathode seven segment LED display
2. 470 Ohm resistors – 7 nos
3. Arduino UNO

Schematic diagram:

Below is the code for the one digit counter

```//Pins for seven segment
int sega = 1;
int segb = 2;
int segc = 3;
int segd = 4;
int sege = 5;
int segf = 6;
int segg = 7;
int dispa = 8;
int dispb = 9;

void setup() {
// Setup code to run once
pinMode(sega,OUTPUT);
pinMode(segb,OUTPUT);
pinMode(segc,OUTPUT);
pinMode(segd,OUTPUT);
pinMode(sege,OUTPUT);
pinMode(segf,OUTPUT);
pinMode(segg,OUTPUT);
pinMode(dispa,OUTPUT);
pinMode(dispb,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
for(int count=0;count<10;count++)
{
digitalWrite(sega,LOW);
digitalWrite(segb,LOW);
digitalWrite(segc,LOW);
digitalWrite(segd,LOW);
digitalWrite(sege,LOW);
digitalWrite(segf,LOW);
digitalWrite(segg,LOW);
if(count==0){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segd,HIGH);
digitalWrite(sege,HIGH);
digitalWrite(segf,HIGH);
}
if(count==1){
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
}
if(count==2){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segg,HIGH);
digitalWrite(sege,HIGH);
digitalWrite(segd,HIGH);
}
if(count==3){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segd,HIGH);
digitalWrite(segg,HIGH);
}
if(count==4){
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segf,HIGH);
digitalWrite(segg,HIGH);
}
if(count==5){
digitalWrite(sega,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segd,HIGH);
digitalWrite(segf,HIGH);
digitalWrite(segg,HIGH);
}
if(count==6){
digitalWrite(sega,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segd,HIGH);
digitalWrite(sege,HIGH);
digitalWrite(segf,HIGH);
digitalWrite(segg,HIGH);
}
if(count==7){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
}
if(count==8){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segd,HIGH);
digitalWrite(sege,HIGH);
digitalWrite(segf,HIGH);
digitalWrite(segg,HIGH);
}
if(count==9){
digitalWrite(sega,HIGH);
digitalWrite(segb,HIGH);
digitalWrite(segc,HIGH);
digitalWrite(segf,HIGH);
digitalWrite(segg,HIGH);
}
delay(1000);
}
}

```