Friday 30 September 2022

Storing the long number(16bits / 32bits) in external flash of arduino or STM32 .

 #include <Wire.h>

#define flashaddress 0x50

int liters = 10058 , add1=10 , add2,time1=55; // value of liters save in flash

byte data , data1;

String liters1 = String(liters); // convert int into string

int result ;    // final value read from flash 

String flashmessage = ""; // convert bytes into string from flash 

char flashincoming; // read each byte from flash

String temperatureString = "";


unsigned int len = liters1.length() + 1; // lenght of string

void setup() {

 Wire.begin();

 Serial.begin(9600);

 Flashwrite();

  

}


void loop() {

   Flashread();

    delay(500);

}





void Flashwrite(){

  byte buff[len];

  Wire.beginTransmission(flashaddress);

  Wire.write(0x00);      //First Word Address

  Wire.write(0x00);      //Second Word Address

  liters1.getBytes(buff, len);  // read total bytes of liters1


for (int i = 0; i < len; i++)

{  Wire.write(buff[i]);

    delay(20);//Write value byte by byte 

  Serial.println(buff[i]);

}



 delay(10);

 Wire.endTransmission();

 delay(10);

  

  

  

  }



void Flashread(){

  Wire.beginTransmission(flashaddress);

 Wire.write(0x00);

 Wire.write(0x00);

 Wire.endTransmission();

 delay(10);


 Wire.requestFrom(flashaddress, len+1);

 delay(10);

  flashmessage = "";

 for(byte i=0; i<len; i++)      //Read 26 data bytes

 {

    flashincoming= Wire.read();

    delay(10);

    flashmessage += String(flashincoming); //convert flash data into string

     

   

  

  

 }

 delay(100);

  Serial.println(flashmessage);

   result = flashmessage.toInt() ;// convert string into int

   if(result==liters){Serial.println("equal");} // if result equal to liters 

   flashmessage = "";

   while(1){

     result++;

     Serial.println(result);

     delay(300);

    }

  

  }  

Thursday 16 December 2021

nrf24L01 data receive and compare with string

 #include <SPI.h>

#include <nRF24L01.h>

#include <RF24.h>


//create an RF24 object

RF24 radio(14, 33);  // CE, CSN


String out, chk="welcome" , red="red" , yellow="yellow";

//address through which two modules communicate.

const byte address[6] = "00001";

const char text2[] = "Hello World";

void setup()

{

  while (!Serial);

    Serial.begin(9600);

  

  radio.begin();

  

  //set the address

  radio.openReadingPipe(0, address);

  

  //Set module as receiver

  radio.startListening();

}


void loop()

{

  //Read the data if available in buffer

  if (radio.available())

  {

    char text[32] = {0};

    radio.read(&text, sizeof(text));

   

    Serial.println(text);

    out=String(text);

    if(out==chk){Serial.println("equal");}

    if(out==red){Serial.println("red colour");}

    if(out==yellow){Serial.println("yellow");}

  }

}

string and char array compare

 String my = "this is red light i need space" , si, read1 , tem="t";

char text, tm="t";

int len;

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  Serial.println();

  char buf[32] = "this is red light i need space";


  Serial.print("Char array: ");

  Serial.println(buf);

  String s = String(buf);

  Serial.print("String: ");

  Serial.println(s);

  if (my == s) {

    Serial.println("equal ");

  }

}

void loop() {

  if (Serial.available() > 0) {

    read1 = Serial.readString();

    text = read1.charAt(2);

      Serial.println(text);

     if(text==tm){Serial.println("temp");}

    len = read1.toInt();


    Serial.println(len);

    if (len == 25000) {

      Serial.println("equal");

    }

  }

}

Monday 13 December 2021

store the double and Float value in I2C eeprom using arduino

 


#include <Wire.h>

#define address 0x50

char va="as";

int val = 100;

byte data;

double lati1 =32.45678;

String lati = String(lati1);  

String myString = "Hello World";


unsigned int len = myString.length() + 1;



void setup()

 Wire.begin();

 Serial.begin(9600);

 delay(1000); 

byte buff[len];

 //WRITE!!!!*******************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address


myString.getBytes(buff, len);


for (int i = 0; i < len; i++)

{  Wire.write(buff[i]);      //Write an 'A'

  Serial.println(buff[i]);

}



 delay(10);


 Wire.endTransmission();

 delay(10);


 //READ!!!!*********************************

 Wire.beginTransmission(address);

 Wire.write(0x00);      //First Word Address

 Wire.write(0x00);      //Second Word Address

 Wire.endTransmission();

 delay(10);


 Wire.requestFrom(address, 1);

 delay(10);

 data = Wire.read();

 Serial.write(data);      //Read the data and print to Serial port

 Serial.println();

 delay(10);

}


void loop()

{

}

string to byte

 String myString = "arduino this was very difficult problem i just solved that ";

 unsigned int len = myString.length() + 1;

 


void setup() {

 Serial.begin(9600);

 char buff[len];

 myString.getBytes(buff, len);

  for (int i = 0; i < len; i++)

{      

  Serial.println(buff[i]);

}

 

}


void loop() {


}


Tuesday 14 April 2020

mosfet as high voltage switch

MOSFET  AS HV  SWITCH.
in most of applications we need to use use mosfet as switch. because mosfet is powerful device which can handle large amount of current. here i will discuss how we can design mosfet switch above 20 voltages.
in present time mosfet use almost in all power  and control systems. where we use voltages above the 20. as you know mosfet work under 20 voltages without any problem . the reason is Vgs.(voltage gate source).in most of applications we use 24 , 48 , 60 , 72 and so on . these voltages are above the common mosfet Vgs which can damage the mosfet. in electric bikes electric cars we use 48 , 60 and 72 dc voltages respectively . here we discuss how to manage proper Vgs.

 
 Pic from google.

in our discussion we will chose IRFP260 mosfet . which is 200v mosfet . it can carry huge current upto 50A.  the Vgs of IRFP260 is 20V. if we use this mosfet under 20 volts we don,t need any extra circuit to minimize Vgs.  
1) First method is using zener diode we can acquire Vgs level. 
In figure there is a 12v zener diode as voltage regulator . here zener diode give fixed 12v . which we use as Vgs . at gate terminal we used a BJP transistor as input switch . apply input signal at Rb . calculate the value of Rz. This circuit can work upto 100v. this switch can be use in solar applications .
P CHANNEL MOSFET AS SWITCH .
In some applications we need p channel mosfet as switch. We can use same method for vgs . the IFRP5210 is p channel mosfet which is 100v and and -40A mosfet 

 
   Pic from google .
 we are using p channel mosfet as switch . zener diode is using as voltage regulator . in this circuit we use a capacitor which minimize the amount of inrush current  


 
This switch is very useful in solar application special MPPT . Buck converters and so on .
Mosfet as switch using voltage regulator.
There is another way we can use voltage regulator . there are several kind of Voltage regulator . which can regulate the voltage from 10VDC to 450VDC .  this method is very easy to acquire the Vgs level .  


constant Vgs level . LM317HV can regulate volatge upto 60. this switch can be use in motor applications. 

There are many types of voltage regulator,s for high voltage for example TL783. it,s maximum input range voltages are 125v .   another is  LR8  . there is LM317 voltage regulator. It,s provide er HV regulate . which input voltage range is 13.3v to 450 v.
APPLICATIONS.
1) MOTOR CONTROLLERES.
2) INDUSTRY HEATERS.
3) SOFT START.
4) SOLAR APPLICATIONS.
5) MPPT.
6) SMPS.
7) INVERTERS .
                                  By usman umer

Storing the long number(16bits / 32bits) in external flash of arduino or STM32 .

 #include <Wire.h> #define flashaddress 0x50 int liters = 10058 , add1=10 , add2,time1=55; // value of liters save in flash byte data ...