P5.js codes in side bloggers

p5.js is a JavaScript library that starts with the original goal of Processing—to make coding accessible for artists, designers, educators, and beginners—and reinterprets this for today's web.

So you have made your p5.js code at your local server or with processing ide, and now you are trying to publish it over internet. Publishing over internet is quite a long process and might cost you a little. Here I have came with a solution to put your processing code over internet using bloggers. Its free and fast, easy to use.

Make your code using p5.js either using local server of using processing ide. After verifying that code, put that inside the given area below. Don,t modify the other codes, you might end-up in errors.

Open bloggers -> themes ->Edit Html ->Paste the code below

Code below:  

<?xml version="1.0" encoding="UTF-8" ?>

<html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>

 <head>

  <meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/> 

  <b:if cond='data:blog.isMobile'> 

   <meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/> 

  <b:else/> 

   <meta content='width=1100' name='viewport'/> 

  </b:if> 

  <b:include data='blog' name='all-head-content'/>

  <title><data:blog.pageTitle/></title>

  <b:skin><![CDATA[

   /* 

    body { 

     font: $(body.font); 

     color: $(body.text.color); 

     background: $(body.background); 

     padding: 0 $(content.shadow.spread) $(content.shadow.spread) $(content.shadow.spread); 

     $(body.background.override) margin: 0; 

     padding: 0; 

    }

   

  ]]></b:skin>

 <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js'/>

    <script>

 <!--Paste in between-->     

      const barWidth = 20;

let lastBar = -1;


function setup() {

  createCanvas(720, 400);

  colorMode(HSB, width, height, 100);

  noStroke();

}


function draw() {

  let whichBar = mouseX / barWidth;

  if (whichBar !== lastBar) {

    let barX = whichBar * barWidth;

    fill(barX, mouseY, 66);

    rect(barX, 0, barWidth, height);

    lastBar = whichBar;

  }

}

<!--Paste in between-->

    </script>

 </head>

<body>

  <b:section class='main' id='main' showaddelement='yes'/>

  </body>

</html>

Using HCSR04 - Ultrasonic Sensor


How the Ultrasonic Sensor works:
Ultrasonic sensors work by emitting sound waves at a frequency too high for humans to hear. They then wait for the sound to be reflected back, calculating distance based on the time of the journey. This is similar to how radar measures the time it takes a radio wave to return after hitting an object.While some sensors use a separate sound emitter and receiver, it’s also possible to combine these into one package device, having an ultrasonic element alternate between emitting and receiving signals. This type of sensor can be manufactured in a smaller package than with separate elements, which is convenient for applications where size is at a premium.
Requirements:

Hardwares
  • Arduino Uno
  • HCSR04 Module
  • Jumper wires
  • LED series with 200 ohm resister(here we will use in-built led on 13 pin)
Softwares
Circuit Diagram

Code to be run:
//In this project, if a object appears in front of Ultrasonic Sensor with in the range 30-50 cm, the led will glow for 5 seconds.

#include <HCSR04.h>

HCSR04 hc(2,3);//initialisation class HCSR04 (trig pin , echo pin)
const int led= 13;
const int uplimit= 50, lowlimit= 30; //Any object between 30cm to 50cm to trigger led//

void setup()
{ 
  Serial.begin(9600); 
  pinMode(13,OUTPUT);
}

void loop()
{ 
  int distance = hc.dist();
  Serial.println(distance); 
  if( (distance>=lowlimit) && (distance<= uplimit))//OBJECT IN RANGE=LED ON FOR 5 SECS
  {
    digitalWrite(led, HIGH);
    delay(5000);
    digitalWrite(led, LOW);
  }
}


Code to Re-Connect Blynkserver Automatically

Issue: Sometimes the hardware(eg. Nodemcu) doesn't connect to router automatically, when there is a break in connection.




Solution: 
In this we'll add a timer. When there is no connection, the timer will start and try to reconnect in every specified time interval. to make this happen we need a library called as simple timer.
Extract this library to the library folder in Arduino folder in my documents.

Write the  following code:

#include <SimpleTimer.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

SimpleTimer timer;    //Creating simple timer variable 

char auth[] = "MxLDc********************KtUI";

char ssid[] = "**********";
char pass[] = "**********";

void setup()
{
  
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000, reconnectBlynk); //Setting interval to 10 seconds to Run function"reconnectBlynk"
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
      BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}
void loop()
{
  
  if (Blynk.connected()) {
    Blynk.run();
  }
  if (!Blynk.connected()) {
    timer.run();
  }
}

IOT Robot with NodeMCU and Arduino using Blynk.

Introduction:

Controlling robots wirelessly is great fun. There are many methods available through which you can control your robot wirelessly.
They are:
  1.  RF remote controller
  2.  Bluetooth signal
  3.  IR signal
  4.  Wifi or IOT etc...
Here I have made a project of robot controlled over IOT using blynk app,arduino and nodemcu.

Things needed

  • Arduino
  • Nodemcu(Esp8266)
  • 2 DC motors and Motor driver
  • LCD display(may or may not added)
  • Batteries or any other power source
  • Blynk Application 
  • Jumper wires etc.

Step 1: Building the Body of Robot

I Build the robot with Sun-board and card board gluing them with super glue. I used old mobile batteries as source and stick them to body. here are some pictures of my build.


Step 2: Connection of different elements

  • Connect two dc motors to the motor driver. for more about motor drivers follow this:https://www.ganeshgadgets.co.in/2017/09/line-follower-part-2-motor-driver.html
  • Connect arduino to the motor driver. use enable of motor driver with PWM inputs of arduino.
  • Power up nodemcu with arduino from 5v pin. Here the idea is when arduino receives digital output from nodemcu at its input pins it would do certain actions.
  • 5 outputs from nodemcu(D0-D4) is fed to 5 pins of arduino(A0 toA5 -here digital pins are used so pin 14 to pin 19).
  • Example when D0 of nodemcu is high, Arduino receives signal and command noter driver to go forward. 
Code example:
if ( digitalRead(a0) == HIGH ) //forward//
 {
  lcd.setCursor(0, 1);
  lcd.print("FORWARD ");
  digitalWrite(af, HIGH);
  digitalWrite(ar, LOW);
  digitalWrite(bf, HIGH);
  digitalWrite(br, LOW);
 }

                   Step 3: Programming Nodemcu and Arduino

                  Code:
                  #include <LiquidCrystal.h>
                  LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //16x2 lcd interface

                  int en = 3;//a-right motor  b-Left motor //
                  int af = 6;int ar = 7;
                  int bf = 5;int br = 4;

                  int a0=14 , a1=15 , a2= 16 ,a3= 17, a4= 18;//from nodemcu D0 to D4//

                  void setup() {
                  lcd.begin(16, 2); 

                   pinMode(en,OUTPUT);
                   pinMode(ar,OUTPUT);pinMode(af,OUTPUT);
                   pinMode(bf,OUTPUT);pinMode(br,OUTPUT);

                   pinMode(a0,INPUT); pinMode(a1,INPUT); pinMode(a2,INPUT);
                   pinMode(a3,INPUT); pinMode(a4,INPUT);

                   digitalWrite(en,HIGH);
                  // loading();
                  }

                  void loop() {
                    
                    if ( digitalRead(a0) == HIGH ) //forward//
                   {
                    lcd.setCursor(0, 1);
                    lcd.print("FORWARD "); 
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, LOW);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, LOW);
                   }
                     if (digitalRead(a1) == HIGH) //backward//
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("BACKWARD"); 
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a2) == HIGH)  //RIGHT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("RIGHT     ");     
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br,LOW);
                        } 
                    if (digitalRead(a3) == HIGH)//LEFT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("LEFT      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar,LOW);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a4) == HIGH)//STOP
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("STOP      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                      }  
                    else
                    {
                    lcd.setCursor(0, 1);
                    lcd.print("        ");          
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                     }
                  } 

                  Conclusion:

                  You can easily build this. you can add lights to the robot and also other features using nodemcu. here is working video of the robot.
                  https://youtu.be/UsY_pJP5PVc

                  Also like and subscribe the channel.

                  RCA composite cable for Raspberry Pi -Solved Problem

                  Converting your old CRT TV to a Raspberry Pie display is matter of great excitement. Raspberry Pi comes with many OS such as Raspbian OS, Retro Gaming OS-"Retropie", Media Centre OS-"OSMC" etc are helping getting good User experience.

                  When it comes to Old CRT TV they don't have in-built HDMI ports Instead they have AV ports. You might have seen AV cable between your set-up box and TV.

                  • To play via R-Pi you need HDMI to AV converter (expensive and not discussed here)
                  or
                    • RCA and AV composite cable
                    What problem arises!!!
                    There is bit difference between pin configuration on Raspberry Pi and other devices. This has been shown below.

                    So it is clear that the pin "video" and "ground"on 3.5mm jack is interchanged in case of RPi. To solve this you should buy RPi specified cables or DIY a female connector like me. So needed item are:
                    • AV female pins
                    • 3.5mm RCA pin
                    • wires and soldering material
                    Solder the wire according to the given figure below.
                    The out come looks like this.

                    Plug it to your TV and enjoy gaming and media like never before. Humming sound may arises due to interference.
                    **In OSMC OS goto setting and find Audio output option, there change the option to AV mode, then you will find zero noise or humming sound.
                    **You can buy readily modified cables at adafruit here thelink.
                    ##Thank you##

                    “SOLAR TRACKER” USING ARDUINO


                    Solar power is renewable energy source and Solar panel helps in converting the solar power to electric power.
                    Solar tracker is a device which is used to sense solar intensity and rotate the solar panel in that respective direction. It would help in getting maximum solar energy through the solar panel and to its electrical conversion.

                    #wiki_stuffs: Orientation and inclination

                    A solar cell performs the best when its surface is perpendicular to the sun's rays, which change continuously over the course of the day and season. It is a common practice to tilt a fixed PV module (without solar tracker) at the same angle as the latitude of array's location to maximize the annual energy yield of module. For example, rooftop PV module at the tropics provides highest annual energy yield when inclination of panel surface is close to horizontal direction.
                    #wiki_stuffs: A solar tracker is a device that orients a payload toward the Sun. Payloads are usually solar panels, parabolic troughs, fresnel reflectors, lenses or the mirrors of a heliostat.
                    Things we need!!
                    • 1.      Solar panel (not necessarily a big one a mini could be better)
                    • 2.      DC motor(servo better if you know coding it)
                    • 3.      Motor driver
                    • 4.      Board, Wood piece or panel holding structure.
                    • 5.      Arduino and jumper wires
                    • 6.      Two IR (Infrared) sensors and resistor and diodes.
                    • 7.      Power source (12V or a power bank might work great)
                    • 8.    Incandescent bulb for testing purpose
                    Whats the Idea??
                    The idea is mounting two sensors and two ends of the solar panel and measuring the solar intensity via Arduino and then Arduino commands to tilt the panel toward that direction in which there is more intensity until the intensity of both the sensors became nearly equal. The tilting action can be done by motor and driving circuit.


                    Concept diagram for solar tracker.



                    Build IR Sensor!!


                    • You can easily find IR Receivers near by electronics store and build the above circuit.
                    • Don't forget to place diodes at output it will decrease interference.
                    • SEE REF:http://www.ganeshgadgets.co.in/2017/08/


                    How it looks when it is built!!





                    Coding!!!
                    Coding is simple one. That is the tilting process going on until the difference between the sensor values become less than desired value.
                    ////////////////////////////Code Solar tracker////////////////////////////////////
                    int br = 3;//motor output reverse
                    int bf = 2;//motor output forward //you can use enable at pwm output or make iy short to 5v.

                    int a4=0,a5=0; //analog sensor input
                    int approx=10; //difference limit
                    void setup() {

                      pinMode(bf,OUTPUT);
                      pinMode(br,OUTPUT);
                      pinMode(A4,INPUT);
                      pinMode(A5,INPUT);
                      Serial.begin(9600);

                    }

                    void loop() {
                     a4=analogRead(A4);
                     a5=analogRead(A5);

                     Serial.print(a4);
                      Serial.print(' ');
                      Serial.print(a5);
                      Serial.print(' ');
                      Serial.print(a5-a4);
                      Serial.println(' ');


                    if(a4>a5)
                    {
                    int diff=a4-a5;
                        if(diff > approx)
                        {
                           digitalWrite(bf,HIGH);
                           digitalWrite(br,LOW);
                        }
                        else{digitalWrite(bf,HIGH);
                             digitalWrite(br,HIGH);}
                     }

                    if(a4<a5)
                    {
                    int diff=a5-a4;
                        if(diff > approx)
                        {
                           digitalWrite(bf,LOW);
                           digitalWrite(br,HIGH);
                        }
                         else{digitalWrite(bf,HIGH);
                             digitalWrite(br,HIGH);}
                      } 
                     delay(50);
                     }
                    //////////////////////////////end//////////////////////////////////////

                    Its a good project for students to start with hope you like it.

                    IOT Switch using NodeMcu and Blynk app

                    The Internet of Things (IoT) is the network of physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, actuators, and connectivity which enables these things to connect, collect and exchange data, creating opportunities for more direct integration of the physical world into computer-based systems, resulting in efficiency improvements, economic benefits, and reduced human exertions.(that's IOT from wiki)

                    A simple beginners IOT based switching action is done in this project.

                    Things we need in this project is:
                    1. NodeMcu
                    2. 1 led with 200ohm resister.
                    3. Arduino IDE and Blynk library
                    4. Blynk App on your phone.

                    What's NodeMcu??
                    NodeMCU is an open source IoT platform.It includes firmware which runs on the ESP8266 Wi-Fi SoC from Espressif Systems, and hardware which is based on the ESP-12 module.The term "NodeMCU" by default refers to the firmware rather than the development kits.(source: https://en.wikiphttps://en.wikipedia.org/wiki/NodeMCUedia.org/wiki/NodeMCU)



                    First try to install NodeMcu board!!
                    1. Go to: tools\board\board manager\esp8266 (search online)
                    else if not found
                    2. goto file\preferences then look for additional board manager urls. paste "http://arduino.esp8266.com/stable/package_esp8266com_index.json" and repeat step-1 install esp8266 board from there.

                    Blynk Library:
                    Search for blynk Library or simply download it from:https://github.com/blynkkk/blynk-library

                    After downloading it:
                    1. Decompress and paste the folder in Arduino library present in documents. (e.g. paste it at C:\Users\*****\Documents\Arduino\libraries
                    2. Start arduino IDE and you can see custom example of BLYNK library at file\examples.
                    3. Connect nodeMce to PC. choose correct board,in my case-NodeMCU 1.0(ESP 12E module). Select the correct COM port(select the com which appears after connecting nodeMcu).
                    4. In arduino IDE go to:files\examples\blynk\boards_wifi\esp8266_standalone.
                    5. 3 things to edit here a-"YourAuthToken", b-"YourNetworkName", c-"YourPassword"
                        'b' is your wifi network name (must connceted to internet) and 'c' is password set for that wifi network.  "YourAuthToken"-this will be discussed later after using the blynk app. After getting the authToken replace it and burn the code to nodeMcu.
                    6. Press reset. Watch connection Status on serial monitor. 

                    Jobs with the blynk App:
                    1. Download blynk App





                    2.Open the app login with FB or other methods.
                    3.Click on New project. Name the project(e.g. Iotswitch_gg). Choose Device: NodeMCU. Then create.
                    4.Authtoken is sent to your mentioned Email. Copy the authtoken and replace it in the code in nodeMCU. You can also get the Authtoken in the project setting.
                    5. Follow the steps in the app.

                    Hope you get it right!!!
                    KEEP VISITING MY BLOG.

                    Blink using 555 timer

                    Have you imagined a blink circuit without arduino!! It was very common using a 555 timer circuit building a flasher or blink circuit.

                    #Requirements:

                    1.555 timer IC
                    2.Capacitor
                    3.Resistors
                    4.Printed Circuit Board
                    5.Wires
                    6.Tools for soldering and 5v power Supply

                    7.Leds

                    1. See the pin diagram of 555 IC.
                    2. Theory behind this.
                    The IC is connected as a astable multivibrator with a duty cycle of about 10%.
                    In figure 1 the LED will be ON for a short period of time and OFF for a longer period. The duty cycle can be reversed if the LED is connected as shown in figure 2 but the battery consumption will also increase due to the fact that the LED will stay ON for a longer period of time.

                    3. Circuit diagram.
                    If you didn't get anything by reading above,you can simply connect the elements according to the circuit diagram given below.
                    The above circuit diagram is copied from internet you can modify this accordingly. So I have replaced higher value resistors with 10k ohm and lower value resistors with 200 ohm and capacitor of 63V/10 uF.
                    Actual Circuit:
                    I suggest that before making the circuit of PCB, you should try it on breadboard for best results and adjust timing of your flasher circuit.
                    I have also brought out additional output pins from leds. You can use them to power up relays and flash bigger lights.
                    To vary resistor you can use variable resistor or a 10k potentiometer and also the capacitor also.

                    for reference:



                    Keep visiting me!!!



                    Codes for adding letters to 8X5 leds

                    Codes for Adding letters to 8X5 LEDs

                    From the last blog we have written codes to On/Off a LED individually. So here I gonna explain how to display letters on leds.
                    The trick is simple and that is by blinking a LED each time. The speed is so fast that it appears that all LEDs are ON at same time.

                    I have used the alphabet patterns or you can say fonts as similar to 16x2 LCD display. So letters will be in 7X5 LEDs matrix.

                    Example:
                    So you can blink LEDs row wise(rows first) or column wise. here shows how can you blink LEDs one by one.
                    Code for Writing 'G' is given below:
                    void Gi()
                    {
                     int a=timel;//duration for which letter will be displayed
                     while( a > 0){
                     onled(1,2); onled(1,3); onled(1,4);
                     onled(2,1); onled(2,5);
                     onled(3,1);
                     onled(4,1); onled(4,3); onled(4,4); onled(4,5);
                     onled(5,1); onled(5,5);
                     onled(6,1); onled(6,5);
                     onled(7,2); onled(7,3); onled(7,4); onled(7,5);
                     a--;
                    }}
                    This code can be used in the last blog I posted using as a function.

                    For the complete code click on link... and thanks for visiting.

                    DIY 8x5 LED Matrix display

                    DIY 8x5 LED Matrix display

                    If you want to make a 8X5 led matrix display without using any other MUX with arduino,then this article is for you.
                    Things you needed:
                    1. bunch of LEDs(check before use)
                    2. PCB Board(Brown board)

                    3. Jumper Wires(Male to female)

                    4. Arduino
                    5. 100 ohms resistors
                    6. Soldering Instrument and Hot glue gun

                    Wiring up/ Circuit connections:
                    Before you start have brief idea about leds:

                    • choose healthy LEDs only
                    • do check before soldering on the PCB.
                    • these needs min 1.5V and a few mA current. So accompany them with 200 or 100 ohm resistance.
                    All you need is connect all Anode of leds in a row together and connect all cathode of leds in a column together. The circuit diagram will clear your thoughts.

                    From the above diagram if the row-x is given Low state and column-y is given High state then the LED belongs to (x,y) will glow.
                    But in programming or using arduino the state of all other leds should be in opposite in order to Switch them off.
                    So the idea is to ON one led at a time and make all other leds OFF that time.

                    Here are some pictures while making the circuit:


                    •  Do add resistances(100 ohm or 200 ohms) otherwise the leds may damage due to over current flow. Add female header pins for make it arduino friendly.

                    CODING:

                    here is the code:

                    int row=0,col=0;
                    int time1=5;
                    int timex=1;
                    void onled(int x,int y)//PASSING ROW AND COLUMN VARIABLES TO ON THE RESPECTIVE LED
                    {
                     reset();
                     if(x==1){row=2;} if(x==2){row=3;} if(x==3){row=4;} if(x==4){row=5;} if(x==5){row=6;} if(x==6){row=7;} if(x==7){row=8;} if(x==8){row=9;}
                     if(y==5){col=19;} if(y==4){col=18;} if(y==3){col=17;} if(y==2){col=16;} if(y==1){col=15;}
                     digitalWrite(row,LOW);
                     digitalWrite(col,HIGH);
                     delay(timex);
                    }
                    void reset()//THIS FUNCTION USED TO SUPPLY ANODE WITH gnd AND CATHODE WITH +5V
                    {
                     digitalWrite(2,HIGH);digitalWrite(3,HIGH);digitalWrite(4,HIGH);digitalWrite(5,HIGH);digitalWrite(6,HIGH);digitalWrite(7,HIGH);digitalWrite(8,HIGH);digitalWrite(9,HIGH);
                     digitalWrite(15,LOW);digitalWrite(16,LOW);digitalWrite(17,LOW);digitalWrite(18,LOW);digitalWrite(19,LOW);
                    }

                    void setup() {
                    Serial.begin(9600);  

                    pinMode(2,OUTPUT);pinMode(3,OUTPUT);pinMode(4,OUTPUT);pinMode(5,OUTPUT);pinMode(6,OUTPUT);pinMode(7,OUTPUT);pinMode(8,OUTPUT);pinMode(9,OUTPUT);
                    pinMode(16,OUTPUT);pinMode(17,OUTPUT);pinMode(18,OUTPUT);pinMode(19,OUTPUT);pinMode(15,OUTPUT);
                    }

                    void loop() {
                     onled(1,1);//on led of row-1 col-1    
                    }
                    The result will look like this:







                    Displaying letters on this will be in the next blog,till then you can use loops for different new patterns.